<?php
	if(!MB_admin){
		exit();
	}
	$recomm = new MBAdminRecomm($host, $root, $pwd, $db);
	$rets = $recomm->showBottomLinks($p, 10);
	$mods = $recomm->getMod(10);
	$modname = $mods['list'][0]['name'];
?>
	<form id="modForm" name="modform" method="post" action="admin_recomm_act.php?a=mod" class="table_header">
		<div class="mods">
			<label>模块名称：</label>
			<input type="text" id="modName" maxlength="20" value="<?php echo htmlencode($modname);?>" name="mn" style="width:280px;" class="txt"/>
			<input type="hidden" name="mp" value="10" />
			<input type="submit" value="确定" class="buttonA"/>
		</div>
		<div><cite>请设置希望在广播大厅中显示的模块名称，点击确定后生效。</cite></div>
	</form>
	<div class="table_header">
		<strong>已设置话题</strong>
		<cite>已设置的话题如下表显示，加粗部分为当前生效的话题。</cite>
		<span><input type="button" value="新建话题" class="buttonA" id="newModule"/></span>
	</div>
	<?php if($rets['count']>0){?>
		<table width="96%" border="0" cellspacing="0" cellpadding="0" align="center" class="tableA">
			<tr>
				<th width="150">链接名</th>
				<th width="150">链接地址</th>
				<th width="100">添加人员</th>
				<th width="100">操作</th>
			</tr>
			<?foreach($rets['list'] as $key => $b):?>
				<tr>
					<td><?php echo htmlencode($b['tit'])?></td>
					<td><?php echo htmlencode($b['st'])?></td>
					<td><?php echo htmlencode($b['uname'])?></td>
					<td><a href="javascript:void(0);" rel="edit" rev="<?php echo $key;?>">编辑</a> <a href="javascript:void(0);" rel="del" rev="<?php echo $b['id'];?>">删除</a></td>
				</tr>
		  <?endforeach?>
		</table>
	<?php }else{?>
		<div class="nodata">目前还没有推荐话题！</div>
	<?php }?>
<?php
	$pages = new MBPage('admin_recomm.php?cid='.$cindex, $rets['count'], $p, 10);
	$pages->showpage();
?>
<script type="text/javascript" >
	var _mlength = <?php echo count($rets['list']);?>;
	function delobj(i){
		$.post('admin_recomm_act.php?a=bl&m=del', {id:i}, function(d){
			eval('r='+d);
			if(r){
				cwin.alert('操作成功！');
			}else{
				cwin.alert('操作成功！');
			}
		});	
	}
	
	var _data = [];
	<?php if($rets['count']>0){?>
		<?php foreach($rets['list'] as $key => $b){?>
		_data.push({
			'id': <?php echo $b['id'];?>,
			'tit': '<?php echo htmlencode($b['tit']);?>',
			'st': '<?php echo htmlencode($b['st']);?>'
		});
		<?php }?>
	<?php }?>
	
	var _html = [
		'<form id="dataForm" name="form1" method="post" action="admin_recomm_act.php?a=bl&m=add">',
		'	<ul class="form">',
		'		<li>',
		'			<strong>链接名：</strong>',
		'			<input type="text" id="htTit" name="t" maxlength="20" class="txt" style="width:140px;" />',
		'			<input type="hidden" id="htId" name="id" value="" />',
		'		</li>',
		'		<li>',
		'			<strong>链接地址：</strong>',
		'			<input type="text" id="sDate" name="l" maxlength="100" class="txt" style="width:140px;" />',
		'		<li>',
		'			<strong></strong>',
		'			<input type="submit" value="确定" class="button"/>',
		'			<input type="reset" value="取消" class="button closeBtn"/>',
		'		</li>',		
		'	</ul>',	
		'</form>'
	];

	var cwin = new moduleObj();
	cwin.autoResize(420, 200);
	cwin.hide();

	$('#modName').keyup(function(){
		var _t = $(this).val();
		if(_t.length>20){
			$(this).val(_t.substring(0, 20));	
		}
	});
	
	$('#modForm').validate({
			errorPlacement: function(label, element) {
				label.appendTo(element.parent())
			},
			rules:{
				mn:{
					required:true,
					maxlength:20
				}
			},
			messages:{
				mn:{
					required:'请填写模块名称',
					maxlength:'模块名称不能超过20个字'
				}
			}
		});			

	$("#newModule").click(function(){
		if($('#dataForm').length == 0){
			cwin.show({title:"添加友情链接", text:_html.join('')});
			$('#dataForm').validate({
					rules:{
						t:{
							required:true,
							maxlength:20
						},
						s1:{
							required:true,
							maxlength:100
						}
					},
					messages:{
						t:{
							required:'请填写链接名',
							maxlength:'链接名不能超过20个字'
						},
						s1:{
							required:'请填写链接地址',
							maxlength:'链接地址不能超过20个字'
						}
					}
				});			
		}else{
			$("#dataForm").attr('action', 'admin_recomm_act.php?a=bl&m=add');
			$('#dataForm label.error').hide();
			$('#htTit').val('');	
			$('#htId').val('');
			$('#sDate').val('');
			cwin.show();
		}
	});

	$('a[rel=edit]').click(function(){
		var no = $(this).attr('rev');
		if($('#dataForm').length == 0){
			cwin.show({title:"修改友情链接",text:_html.join('')});
			$("#dataForm").attr('action','admin_recomm_act.php?a=bl&m=edit');
			$('#htTit').val(_data[no].tit);	
			$('#htId').val(_data[no].id);
			$('#sDate').val(_data[no].st);
			$('#dataForm').validate({
					rules:{
						t:{
							required:true,
							maxlength:20
						},
						s1:{
							required:true,
							maxlength:100
						}
					},
					messages:{
						t:{
							required:'请填写链接名',
							maxlength:'链接名不能超过20个字'
						},
						s1:{
							required:'请填写链接地址',
							maxlength:'链接地址不能超过20个字'
						}				
					}
				});			
		}else{
			cwin.show({title:"修改友情链接"});
			$("#dataForm").attr('action','admin_recomm_act.php?a=bl&m=edit');
			$('#htTit').val(_data[no].tit);	
			$('#htId').val(_data[no].id);
			$('#sDate').val(_data[no].st);
			$('#addArea').fadeIn("slow");				
		}		
	});

	$('a[rel=del]').click(function(){
		var no = $(this).attr('rev');
		cwin.config('确定要删除此项?','delobj('+no+')');			
	});	
</script>
